package com.flx.at.spring.code.trans.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.stream.IntStream;

@Repository
public class UserDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 用户收到钱
     */
    public int addMoney(String custom,int money){
        String sql = "update user_money set money=money+? where custom = ?";
        return jdbcTemplate.update(sql,money,custom);
    }

    /**
     * 向T1表添加1w条记录
     * @return
     */
    public int addT1(){
        IntStream.rangeClosed(1,10000).forEach(x->{
            System.out.println("addT1 "+x);
            jdbcTemplate.update("insert t1(`a`,`b`) values(?,?)",x,x);
        });
        return 0;
    }

    public int addT2(){
        IntStream.rangeClosed(1,100).forEach(x->{
            System.out.println("addT2 "+x);
            jdbcTemplate.update("insert t2(`a`,`b`) values(?,?)",x,x);
        });
        return 0;
    }

}
